<?php

class CGetFilters{
    public $pdodbobj;
    public $connstatus=false;
    public $eLog;
    function __construct() {
       try{ 
            $this->pdodbobj= new DB();
            $this->connstatus=$this->pdodbobj->connect();
            if($this->pdodbobj!=null){
                
            }
            else{
                die("Connection failed");
            }
            
        }
        catch(Exception $ex){
            die('GetFilters:__construct():: \t'. $ex->getMessage(). "\n");   
        } 
    }
    
    public function getFilters($filterType,$statusid=1,$ignorekeys=false){
        $filterTable="af_privacy_types";
        $ignoreKeysFor="";
        if($filterType=="privacy_types"){
            $filterTable="af_privacy_types";  
            if($ignorekeys){
                 $ignoreKeysFor=" and keyword not in('choose_cluster','specific_friend') ";
            } 
        }
        else if("share_with"){
            $filterTable="af_user_share_dropdowns";
            $ignoreKeysFor="";
        }
        
        $selquery="select * from ".$filterTable." where status=:statusid ".$ignoreKeysFor;
        $fetcRecords= $this->pdodbobj->fetch_array(
                            $this->pdodbobj->query($selquery,
                                                     array(
                                                     ":statusid"=>$statusid
                                                     )
                                                   ));
    //$postStatusTypes->reportAbuse->Remove_Media_I_Dont_Like_This
        if(is_array($fetcRecords) && count($fetcRecords)>0 ){
            return $fetcRecords;
        }
        else{
            return array();
        }
    }
    
    public function getClusters($userId,$statusid=1){
        $filterTable="af_clusters";        
        $selquery="select * from ".$filterTable." where status=:statusid and Created_By_ID=:userid";
        $fetcRecords= $this->pdodbobj->fetch_array(
                            $this->pdodbobj->query($selquery,
                                                     array(
                                                     ":statusid"=>$statusid,
                                                     ":userid"=>$userId
                                                     )
                                                   ));
    //$postStatusTypes->reportAbuse->Remove_Media_I_Dont_Like_This
        if(is_array($fetcRecords) && count($fetcRecords)>0 ){
            return $fetcRecords;
        }
        else{
            return array();
        }
    }
    
    public function getClusterFriends($userId,$clusterId,$statusid=1){
        $selquery="SELECT u.User_ID
			        FROM 
			            af_cluster_friends as cf,
			            af_users as u 
			        WHERE 
			            u.User_ID=cf.Friend_ID
			                and
			            cf.Added_By_User_ID=:userid 
			                and 
			            cf.Cluster_ID=:clusterid
			                and 
			            cf.Status=:statusid
            		";
        $fetcRecords= $this->pdodbobj->fetch_array(
                            $this->pdodbobj->query($selquery,
                                                     array(
                                                     ":statusid"=>$statusid,
                                                     ":userid"=>$userId,
                                                     ":clusterid"=>$clusterId
                                                     )
                                                   ));
    //$postStatusTypes->reportAbuse->Remove_Media_I_Dont_Like_This
        if(is_array($fetcRecords) && count($fetcRecords)>0 ){
            return $fetcRecords;
        }
        else{
            return array();
        }
    }
    
    
    public function getReportAbuseTypes($userId,$statusid=1){
        $filterTable="af_report_abuse_types";        
        $selquery="select * from ".$filterTable." where Status=:statusid";
        $fetcRecords= $this->pdodbobj->fetch_array(
                            $this->pdodbobj->query($selquery,
                                                     array(
                                                     ":statusid"=>$statusid
                                                     )
                                                   ));
    //$postStatusTypes->reportAbuse->Remove_Media_I_Dont_Like_This
        if(is_array($fetcRecords) && count($fetcRecords)>0 ){
            return $fetcRecords;
        }
        else{
            return array();
        }
    }
    
    public function getPostReportAbuseTypes($userId,$postId){
        $filterTable="af_friends_posts_settings";        
        $selquery="select Report_Abuse_IDs,Status,Is_Approved_By_Admin from ".$filterTable." where User_ID=:User_ID and Post_ID=:postid";
        $fetcRecords= $this->pdodbobj->fetch_array(
                            $this->pdodbobj->query($selquery,
                                                     array(
                                                     ":postid"=>$postId,
                                                     ":User_ID"=>$userId
                                                     )
                                                   ));
        //echo "$selquery"." userid: ".$userId." postid: ".$postId;
        //die();
    //$postStatusTypes->reportAbuse->Remove_Media_I_Dont_Like_This
        if(is_array($fetcRecords) && count($fetcRecords)>0 ){
            return $fetcRecords;
        }
        else{
            return array();
        }
    }   
                       
}

function getScriptLocatedAbsolutePath(){
    $protocol="http://";
    if(strstr($_SERVER["SERVER_PROTOCOL"],"HTTPS")){
        $protocol="https://";    
    }
    
    $filepatharr=explode("/",$_SERVER['PHP_SELF']);
    $filename=end($filepatharr);
    return ($protocol.$_SERVER["SERVER_NAME"]."/".str_replace($filename,"",$_SERVER['PHP_SELF']));    
}
?>